package com.fr.data.core.db.dialect;

import java.sql.Connection;

public class MSSQLDialect extends AbstractDialect
{
  private String defaultAutoIncrease = "identity(1,1)";

  public MSSQLDialect()
  {
    this.left_quote = "[";
    this.right_quote = "]";
  }

  public String createSequence(Connection paramConnection, String paramString1, String paramString2, String paramString3)
  {
    return paramString3 + " " + this.defaultAutoIncrease;
  }

  protected String getIdentitySelectString()
    throws Exception
  {
    return "select @@identity";
  }

  public boolean supportsLimit()
  {
    return true;
  }

  public boolean supportsLimitOffset()
  {
    return false;
  }

  public String getLimitString(String paramString, int paramInt1, int paramInt2)
  {
    if (paramInt1 > 0)
      throw new UnsupportedOperationException("query result offset is not supported");
    return new StringBuffer(paramString.length() + 16).append(paramString).insert(getAfterSelectInsertPoint(paramString), " top " + paramInt2).toString();
  }

  static int getAfterSelectInsertPoint(String paramString)
  {
    int i = paramString.toLowerCase().indexOf("select");
    int j = paramString.toLowerCase().indexOf("select distinct");
    return (i + ((j == i) ? 15 : 6));
  }
}